#include "stdafx.h"
#include "TestCase.h"
#include <vector>
#include <string>

struct TestCaseData
{
	ITestCase* testCase;
	std::string name;
};

typedef std::vector<TestCaseData> TestCaseList;
TestCaseList g_testCases;

#define REGIEST_TEST_CASE(TESTCASE)	\
	TestCaseData data;						\
	data.testCase = new TESTCASE();			\
	data.name = #TESTCASE;						\
	g_testCases.push_back(data);			

void regiserAllTestCase()
{
	g_testCases.clear();
	REGIEST_TEST_CASE(TestSylphSystem);
}

void releaseAllTestCase()
{
	TestCaseList::iterator itor = g_testCases.begin();
	TestCaseList::iterator itend = g_testCases.end();

	for( ; itor != itend; ++itor)
	{
		if(itor->testCase)
		{
			delete itor->testCase;
			itor->testCase = NULL;
		}
	}

	g_testCases.clear();
}

int main(int argc, char* argv[])
{
	regiserAllTestCase();

	printf_s("***********************************************************\n");

	for( size_t i = 0; i < g_testCases.size(); ++i)
	{
		printf_s("%d %s\n", i + 1, g_testCases[i].name.c_str());
	}

	printf_s("***********************************************************\n");

	printf_s("Please input the test case index: \n");

	size_t index = 0;
	while(true)
	{ 
		scanf_s("%d", &index);
		if(index > 0 && index <= g_testCases.size())
		{
			break;
		}
		else
		{
			printf_s("Error Index! Please input the test case index: \n");
		}
	}

	g_testCases[index - 1].testCase->run();

	releaseAllTestCase();

	return 0;
}